Daniel Lupercio HW2

c) Build the input pipeline, including the appropriate preprocessing operations, and optionally add data augmentation

This takes approximately 42 seconds to run

Lets find shape of our traing data.

As you see, The Training data is in shape of (Number of Training Images, Width of image, Height of image, Channel of image). This shape is very important. If you do not resize the images to same size. It should be (No. of images,) shape. So, using this shape you cant feed the images to the model.

Let us look some random images of our dataset.

b) Split it into a training set, a validation set, and a test set.

We already have a training set. If we pass through the test set directory, we can return the testing images. We can create the validation set from the training set. Let's give that a shot here. I will subset the last 600 images from the training set. I can not ensure that 100 images of each class are in this validation set.

That seemed to work, so lets plot some of the images from the validation set

Now lets get the images from the testing directory.

I am not sure if the size difference in the train, test and validation sets will create any difficulty in creating the models later.

Now, Create the CNN model to predict the class labels.This is the basic CNN model. Getting the test images took approximately 9 seconds.

Lets plot the testing sets to ensure we have properly imported them

(d) Fine-tune a pretrained model on this dataset.

I originally wanted to follow along the HOML Ch.14 sections: Pretrained Models for Transfer Learning for this part of the problem. That led me to define the train_dataset_size, valid_dataset_size, batch_size and n_classes. Then when it came time to run the history = model.fit(...). I ran into some errors: "ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()". This is something to do with the way my train_images array was created. I attempted to convert the values from uint8 to float32 using 'tf.image.convert_image_dtype'. But that conversion returned the same error.

I will admit that the amount of convolutional layers will lead me to belive that this model will overfit the data.

Each epoch took approximately 30 minutes to complete

To my point above, the model accuracy for both the train and testing sets increased with the number of epochs.

To evaluate a model, there are many methods are proposed to evaluate the model. I use Accuracy to evaluate the performance of my model.

We are returned a model accuracy of approximately 80% on the test set

The get_image() function does not work here because the seg_pred directory is not split into folders of the photo types. The directory is filled with images of numeric labels.

A different get_images() function had to be created for the prediction images because these images are not in a directory with the proper labels. Thus, we need to read the images from the one directory they exist in.

this took approximately 23 seconds to run

For some reason, pred_images.shape will return an error. pred_images_2 was created as an np.array even though I defined the images to be arrays in the function.

Following image shows the predicted class label on top of the image and probabilities below of the image.

Class labels : 0 for Building , 1 for forest, 2 for glacier, 3 for mountain, 4 for Sea , 5 for Street

I was not able to display the labels of each image because "get_classlabel" returns an "unhashable type: 'numpy.ndarray'" error.

Code not used or not compatible with this assignment